\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b0\i0\ul0\fs28 server memory postscript vm NXShowAllWindows ProcessMonitor\
\
Q: How can I tell how much window server memory my application is using?\
Some Application Kit programs can use a significant number of windows and\
bitmaps, and the memory used in these cases isn't easy to trace.\
\
\b For 1.0
\b0 \
A: Check out the following two files (wsmemory.psw and wsmem.h), which define the interface and source code for a routine called NXWindowServerMemory(). This is a function which returns the amount of PostScript VM and window backing store is used by your application at the time you call it. These files use published interfaces and are freely distributable. Developers are encouraged to make these measurements by compiling and linking in this code. \
\
Another way to trace the windows created by an appliction is to run applications with the NXShowAllWindows switch set to YES. (You can either run the application from a Shell to accomplish this or just set the default value with dwrite.) This switch causes all windows created in the server to be displayed on the screen and makes them non-buffered so you can see all drawing as it happens.\
\
---wsmem.h---\
\f3\fs24 \
\f1\b /*\
Copyright (c) 1990 NeXT, Inc.\
All Rights Reserved.\
\
wsmem.h\
Procedure prototype for NXWindowServerMemory\
Leovitch 06Jan90\
\
Synopsis:\
\
int NXWindowServerMemory(DPSContext *context,\
int *vmUsedP, int *windowBackingP,\
NXStream *windowDumpStream);\
\
NXWindowServerMemory calculates the amount of window\
server memory being used at the moment by the window\
server context given as context. If NULL is passed for\
the context, the current context is used. The amount\
of PostScript VM used by the current context is returned\
in the int pointed to by vmUsedP; the amount of window\
backing store used by windows owned by the current\
context is returned in the int\
pointed to by windowBackingP. The sum of these two numbers\
is the amount of the window server's memory which this\
PostScript context is responsible for.\
\
In order to calculate these numbers, NXWindowServerMemory\
uses the PostScript operators dumpwindows and vmstatus.\
NXWindowServerMemory takes a substantial fraction of a \
second to execute; thus, calling this function\
in normal operation is not recommended. It should be used\
for debugging and performance analysis purposes.\
\
If a non-NULL value is passed in for windowDumpStream, then\
the information returned from the dumpwindows operator\
is echoed to the NXStream given. This can be useful for\
finding out more about which windows are using up your\
storage.\
\
Return Value\
\
Normally, NXWindowServerMemory returns 0. If NULL is passed\
for context and there is no current DPS Context, -1 is returned.\
\
*/\
\
int NXWindowServerMemory(DPSContext context,\
int *vmUsedP, int *windowBackingP,\
NXStream *windowDumpStream);\
\f3\b0 \
\
\f2\fs28 ---wsmemory.psw---
\fs24 \
\
\f1\b /*\
Copyright (c) 1990 NeXT, Inc.\
All Rights Reserved.\
\
wsmemory.psw\
\
This module defines the function NXWindowServerMemory,\
which will return the amount of window server memory\
being used by the current window server context.\
\
Synopsis:\
\
int NXWindowServerMemory(DPSContext *context,\
int *vmUsedP, int *windowBackingP,\
NXStream *windowDumpStream);\
\
NXWindowServerMemory calculates the amount of window\
server memory being used at the moment by the window\
server context given as context. If NULL is passed for\
the context, the current context is used. The amount\
of PostScript VM used by the current context is returned\
in the int pointed to by vmUsedP; the amount of window\
backing store used by windows owned by the current\
context is returned in the int\
pointed to by windowBackingP. The sum of these two numbers\
is the amount of the window server's memory which this\
PostScript context is responsible for.\
\
In order to calculate these numbers, NXWindowServerMemory\
uses the PostScript operators dumpwindows and vmstatus.\
It takes some time to execute; thus, calling this function\
in normal operation is not recommended.\
\
If a non-NULL value is passed in for windowDumpStream, then\
the information returned from the dumpwindows operator\
is echoed to the NXStream given. This can be useful for\
finding out more about which windows are using up your\
storage.\
\
Return Value\
\
Normally, NXWindowServerMemory returns 0. If NULL is passed\
for context and there is no current DPS Context, -1 is returned.\
\
*/\
\
#import <strings.h>\
#import <stdlib.h>\
#import <streams/streams.h>\
#import <dpsclient/dpsclient.h>\
\
/* These three variables define a buffer filled by _NXMyTextProc below,\
and parsed by the NXWindowServerMemory procedure. */\
static char *responseBuffer; /* Pointer to character buffer */\
static int responseBufCount; /* Number of bytes in buffer currently */\
static int responseBufSize; /* Total size of buffer */\
#define MINRESPBUFSIZE 500\
\
/* Prototype for _NXMyTextProc; implementation is below NXWindowServerMemory */\
static void _NXMyTextProc(\
DPSContext context, \
char *buf, \
long unsigned int count);\
\
/*\
_NXvmstatus is a pswrap which calls the vmstatus operator after\
doing a private VM garbage collection. You need to do a garbage\
collection in order to get consistent results from the vmstatus\
/* And null-terminate the buffer (this is used by the main procedure) */\
*(responseBuffer+responseBufCount) = 0;\
\} /* _NXMyTextProc */\
\f3\b0 \
\f2\b\fs28 For 2.0
\b0 \
A: There is a new application located under /NextDeveloper/Apps/ProcessMonitor which will allow you to measure and analyze your application's memory usage. In particular, the Display Postscript Inspector shows the amount of backing store and virtual memory used by your Application. A monitor panel displays these information in graphical form. Please refer to the documentation under /NextLibrary/Documentation/NextDev/DevTools/04_DevApps/ProcessMonitor.rtfd for further information. You can use the Digital Librarian and search for the keyword ProcessMonitor to bring this document on-line. \